/*******************************************************************************
 * Copyright (c) 2010, 2030 www.itlaobing.cn
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package cn.itlaobing.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;

import cn.itlaobing.entity.UserEntity;
import cn.itlaobing.util.IRowMapper;

/** 
 * ClassName: UserDap <br/> 
 * Function: TODO 功能描述 <br/> 
 * date: 2017年11月1日 上午11:06:49 <br/> 
 * 
 * @author 王博 
 * @version  
 * @since JDK 1.8 
 */
public class UserDao extends BaseDao<UserEntity> {
	
	/** 
	 * queryNameandPwd:(根据用户名或者电话和密码查询用户信息). <br/>
	 * 
	 * @author 王博 
	 * @param name
	 * @param pwd
	 * @return
	 * @throws SQLException 
	 * @since JDK 1.8 
	 */  
	public UserEntity queryNameandPwd(String name,String pwd) throws SQLException {
		String sql="select id,account,pwd,logintime,nickname,cellphone from tbl_user where (account=? or cellphone=?) and pwd=?";
		List<UserEntity> listuser=db.executeQuery(sql, new IRowMapper<UserEntity>() {
			@Override
			public UserEntity rowMapper(ResultSet rs) throws SQLException {
				UserEntity ue=new UserEntity(rs.getInt("id"),
						rs.getString("account"),
						rs.getString("pwd"),
						rs.getDate("logintime"),
						rs.getString("nickname"),
						rs.getString("cellphone"));
				return ue;
			}
		}, name,name,pwd);
		System.out.println(listuser.get(0).toString());
		return listuser.get(0);
	}
	
	/** 
	 * updatePlaceOrder:(更改用户上次登录时间). <br/>
	 * 
	 * @author 王博 
	 * @return 
	 * @throws SQLException 
	 * @since JDK 1.8 
	 */  
	public int updatePlaceOrder(Date date,int id) throws SQLException {
		String sql="UPDATE tbl_user SET logintime=? WHERE id=?";
		return db.executeUpdate(sql, date,id);
	}

}
